﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using DALScolarite;
namespace Scolarite 
{
    public partial class FicheEtudiant : Form
    {
       
        public  modeload loadingmod;
        public long idetudiants = 0;
        public FicheEtudiant()
        {
            InitializeComponent();
        }

        private void prenomFRLabel_Click(object sender, EventArgs e)
        {

        }

        private void prenomFRTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

          /*  FileStream fs;
            BinaryReader br;

            string FileName = CSVFileNameTextBox.Text;
            byte[] ImageData;
            fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
            br = new BinaryReader(fs);
            ImageData = br.ReadBytes((int)fs.Length);*/


            scolarite_etudiants addetudiant = new scolarite_etudiants
            {
                cin = cinTextBox.Text,
                NomAR = nomARTextBox.Text,
                NomFR = nomFRTextBox.Text,
                PrenomAR = prenomARTextBox.Text,
                PrenomFR= prenomFRTextBox.Text,
                idStatusEtudiant = idStatusEtudiantComboBox.SelectedValue.ToString(),
                // sex = sexComboBox.SelectedValue.ToString(),
                photo = CSVFileNameTextBox.Text/*,
                photobin = ImageData*/

            };

            GlobalParams.MonDbcontext.scolarite_etudiants.Add(addetudiant);
            GlobalParams.MonDbcontext.SaveChanges();
            

        }

        private void FicheEtudiant_Load(object sender, EventArgs e)
        {
            scolarite_statusetudiantBindingSource.DataSource = GlobalParams.MonDbcontext.scolarite_statusetudiant.ToList();
             
            
            if (this.loadingmod == modeload.AJOUT)
            {
                scolarite_etudiantsBindingSource.DataSource = GlobalParams.MonDbcontext.scolarite_etudiants.ToList();
                scolarite_etudiantsBindingSource.AddNew();
            }
            else if (this.loadingmod == modeload.INFO &&  this.idetudiants != 0 )
            {
                scolarite_etudiantsBindingSource.DataSource = GlobalParams.MonDbcontext.scolarite_etudiants.Where(et => et.idetudiants == idetudiants).ToList();

            }
        }

        private void emailTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void codecnssTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void btcsvfile_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Filter = "Image files | *.jpg";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    CSVFileNameTextBox.Text = openFileDialog1.FileName;
                    pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
